﻿using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Reflection;
using QbservableCore.Serialization.Helpers;
using System.Runtime.Serialization;

namespace QbservableCore.Serialization
{
    [DataContract]
    public abstract class MemberBindingNodeBase
    {
        [DataMember]
        public SerializableMemberInfo MemberToken { get; set; }

        [DataMember]
        public string MemberName { get; set; }

        [DataMember]
        public MemberBindingType BindingType { get; set; }

        protected internal MemberBinding ToMemberBinding(ExepressionBuilderCache exepressionBuilderCache)
        {
            MemberInfo member = MemberToken.Deserialize();
            return ToMemberBindingCore(exepressionBuilderCache, member);
        }

        protected internal abstract MemberBinding ToMemberBindingCore(ExepressionBuilderCache exepressionBuilderCache, MemberInfo member);

        protected internal abstract void TraverseChildren(Func<ExpRepresentationBase, ExpRepresentationBase> action);
    }
}